package com.demo.minademo;

import org.apache.mina.core.session.IoSession;

public class SessionManager {

    private static SessionManager mInstance = null;

    private IoSession mSession;

    public static SessionManager getInstance(){
        if(mInstance == null){
            synchronized (SessionManager.class){
                if(mInstance == null){
                    mInstance = new SessionManager();
                }
            }
        }
        return mInstance;
    }

    public IoSession getSession() {
        return mSession;
    }

    public void setSession(IoSession session) {
        mSession = session;
    }

    public void writeToService(Object msg){
        if(mSession != null){
            mSession.write(msg);
        }
    }

    public void closeSession(){
        if(mSession != null){
            mSession.closeOnFlush();
        }
    }

    public void removeSession(){
        this.mSession = null;
    }
}
